<?php

/**
 * This is the model class for table "lths_b_usertype".
 *
 * The followings are the available columns in table 'lths_b_usertype':
 * @property integer $usertype_code
 * @property string $usertype_name
 * @property string $remark
 * @property string $create_time
 * @property string $update_time
 *
 * The followings are the available model relations:
 * @property TradeTreaty[] $tradeTreaties
 */
class BUsertype extends ParamModel
{
	
	public $keyname='usertype_code';
	public $displayname='usertype_name';
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return BUsertype the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
	
	public function getListDataTreaty()
	{
		$results = array();
		$criteria=new CDbCriteria;
		$criteria->compare('usertype_code',array('1','2','3','4'));
		$models = $this->findAll($criteria);
	    foreach ($models as $key => $value) {
	    	$results[$value[$this->keyname]] = $value[$this->displayname];
	    }
	    return $results;
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'lths_b_usertype';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('usertype_code', 'required'),
			array('usertype_code', 'numerical', 'integerOnly'=>true),
			array('usertype_name', 'length', 'max'=>50),
			array('remark', 'length', 'max'=>100),
			array('create_time, update_time', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('usertype_code, usertype_name, remark, create_time, update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tradeTreaties' => array(self::HAS_MANY, 'TradeTreaty', 'trade_user_type'),
			'producttypes' => array(self::MANY_MANY, 'Producttype', 'lths_usertype_producttype(usertype_code, producttype_code)','order'=>'producttypes.show_order'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'usertype_code' => 'Usertype Code',
			'usertype_name' => 'Usertype Name',
			'remark' => 'Remark',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('usertype_code',$this->usertype_code);
		$criteria->compare('usertype_name',$this->usertype_name,true);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}